#!/bin/bash

# Dynamic Range Reconfiguration Examples
# This script demonstrates the new dyn-range functionality with intelligent F and random L

echo "=== Turritopsis Dynamic Range Reconfiguration Examples ==="
echo

# Example 1: Scale up from N=4 to N=13 with fixed L=1
echo "Example 1: Scale up from N=4 to N=13 (F auto, L fixed=1)"
echo "Command: ./turritopsis_full --epochs 10 --r 3 --n 4 --f 1 --dyn-range 4,13 --dyn-l 1"
echo "Expected: N=4→6→8→10→12→13, F=1→1→2→3→3→4, L=1 (fixed)"
echo

# Example 2: Scale down from N=17 to N=4 with random L
echo "Example 2: Scale down from N=17 to N=4 (F auto, L random 0-2)"
echo "Command: ./turritopsis_full --epochs 15 --r 3 --n 4 --f 1 --dyn-range 17,4 --dyn-l-max 2 --dyn-seed 123"
echo "Expected: N=17→15→13→11→9→7→5→4, F=5→4→4→3→2→2→1→1, L=random(0-2)"
echo

# Example 3: Moderate scale from N=7 to N=15 with L=0
echo "Example 3: Moderate scale from N=7 to N=15 (F auto, L fixed=0)"
echo "Command: ./turritopsis_full --epochs 20 --r 4 --n 4 --f 1 --dyn-range 7,15 --dyn-l 0"
echo "Expected: N=7→8→9→10→11→12→13→14→15, F=2→2→2→3→3→3→4→4→4, L=0 (fixed)"
echo

# Example 4: Small scale from N=5 to N=9 with random L
echo "Example 4: Small scale from N=5 to N=9 (F auto, L random 0-1)"
echo "Command: ./turritopsis_full --epochs 8 --r 2 --n 4 --f 1 --dyn-range 5,9 --dyn-l-max 1 --dyn-seed 789"
echo "Expected: N=5→6→7→8→9, F=1→1→2→2→2, L=random(0-1)"
echo

echo "=== Key Features ==="
echo "1. Intelligent F calculation: F = floor((N-1)/3) for safety"
echo "2. Configurable L: --dyn-l for fixed L, --dyn-l-max for random L"
echo "3. Safety verification: n >= 3f + 2l + 1 for all epochs"
echo "4. Linear interpolation: Smooth N transition between startN and endN"
echo "5. Reproducible: Same seed produces same L sequence (when using random L)"
echo

echo "=== Safety Inequality Examples ==="
echo "N=4, F=1: 4 >= 3*1 + 2*0 + 1 = 4 ✓"
echo "N=7, F=2: 7 >= 3*2 + 2*1 + 1 = 9 ✗ (L=1 too high)"
echo "N=7, F=2: 7 >= 3*2 + 2*0 + 1 = 7 ✓ (L=0 safe)"
echo "N=13, F=4: 13 >= 3*4 + 2*0 + 1 = 13 ✓"
echo

echo "=== Usage Tips ==="
echo "1. Use --dyn-l for fixed L value, --dyn-l-max for random L"
echo "2. Use --dyn-seed for reproducible random L experiments"
echo "3. Monitor KR execution points (every R epochs)"
echo "4. Check metrics files for N/F/L progression"
echo "5. Compare with static scenarios for performance analysis"
echo "6. Fixed L is useful for controlled experiments, random L for stress testing"
